package homework.day06;

import java.io.*;
import java.nio.charset.StandardCharsets;

/**
 * 改正下面程序的错误
 * <p>
 * 向文件testpw.txt中以UTF-8编码写入一行字符串：
 * 你好!我喜欢java!
 * <p>
 * 单词记一记:
 * print 打印
 *
 * @author Xiloer
 */
public class Test03 {
    //	try {
//	FileOutputStream fos = new FileOutputStream("testpw.txt");
//	OutputStreamWriter osw = new OutputStreamWriter(fos,"UFT-8");
//	BufferedWriter bw = new BufferedWriter(osw);
//	PrintWriter pw = new PrintWriter(bw);
//	
//	pw.println("你好!我喜欢java!");
//	system.out.println("写出完毕!");
//	}catch(Exception e) {
//		System.out.println("出错了!");
//	}
    public static void main(String[] args) {
        FileOutputStream fos=null;
        try {
             fos = new FileOutputStream("testpw.txt");
            //StandardCharsets.UTF_8"是Java编程语言中的一个类，用于表示UTF-8编码的字符集。
            OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
            BufferedWriter bw = new BufferedWriter(osw);
            PrintWriter pw = new PrintWriter(bw,true);

            pw.println("你好!我喜欢java!");
            //首字母大写
            System.out.println("写出完毕!");
        }catch(Exception e) {
            System.out.println("出错了!");
    }


    }
}
